//
//  CXHMacro.h
//  CXHCore
//
//  Created by Cdionysus on 2018/12/13.
//  Copyright © 2018年 Cdionysus. All rights reserved.
//

#ifndef CXHMacro_h
#define CXHMacro_h

#define CXH_SUPPRESS_PERFORM_SELECTOR_LEAK_WARNING(code) \
    _Pragma("clang diagnostic push") \
    _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
    code; \
    _Pragma("clang diagnostic pop")

#ifndef CXH_dispatch_main_async_safe
#define CXH_dispatch_main_async_safe(block)    \
    if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) { \
        block();    \
    } else {    \
        dispatch_async(dispatch_get_main_queue(), block);   \
    }
#endif


#define kCXHStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || ![str isKindOfClass:[NSString class]] || [str length] < 1 ? YES : NO)
#define kCXHArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || ![array isKindOfClass:[NSArray class]] || array.count == 0)
#define kCXHDictIsEmpty(dict) (dict == nil || [dict isKindOfClass:[NSNull class]] || ![dict isKindOfClass:[NSDictionary class]] || dict.allKeys.count == 0)
#define kCXHObjectIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))

// 机型UI适配宏
#define kIPhoneX (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && (kScreenWidth == 375.0 && kScreenHeight == 812.0))
#define kIphoneXS (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && (kScreenWidth == 375.0 && kScreenHeight == 812.0))
#define kIphoneXR (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && (kScreenWidth == 414.0 && kScreenHeight == 896.0) && (kScreenScale == 2))
#define kIphoneXS_MAX (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && (kScreenWidth == 414.0 && kScreenHeight == 896.0) && (kScreenScale == 3))
#define kCurveScreen (kIPhoneX || kIphoneXS || kIphoneXR || kIphoneXS_MAX) // 刘海屏幕
#define kNavBarHeight ([UIDevice currentDevice].CXH_isPad ? 50 : 44)
#define kTopBarHeight (kStatusBarHeight + kNavBarHeight)
#define kTabBarHeight (kCurveScreen ? 83 : 49)

#endif /* CXHMacro_h */
